package com.wyy.controller;

import com.wyy.beans.Car;
import com.wyy.service.CarService;
import com.wyy.common.Result;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class CarController {

    @Autowired
    private CarService carService;

    @PostMapping("/car")
    @RequiresRoles("admin")
    public Result<Car> addCar(@RequestBody Car car){
        return carService.addCar(car);
    }

    @DeleteMapping("/car/{licensePlateNo}")
    @RequiresRoles("admin")
    public Result<Car> deleteCar(@PathVariable String licensePlateNo){
        return carService.deleteCar(licensePlateNo);
    }

    @GetMapping("/car/{licensePlateNo}")
    public Result<Car> getCar(@PathVariable String licensePlateNo){
        return carService.getCar(licensePlateNo);
    }

    @GetMapping("/cars")
    public Result<List<Car>> getCars() {
        return carService.getCars();
    }

    @GetMapping("/cars/{telephoneNumber}")
    public Result<List<Car>> getCarsByTelephone(@PathVariable String telephoneNumber) {
        return carService.getCarsByUserTelephone(telephoneNumber);
    }

}
